package com.qqt.csr.route.vo.req;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.google.common.collect.Lists;
import com.qqt.csr.common.enums.YesOrNotEnum;
import com.qqt.csr.common.idempotent.RequestKeyParam;
import com.qqt.csr.common.operalog.OperaLogSchema;
import com.qqt.csr.route.entity.RouteBizRule;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import lombok.*;
import lombok.experimental.Accessors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.data.mongodb.core.mapping.FieldType;

import java.io.Serial;
import java.io.Serializable;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

/**
 * 客服路由分发规则
 */
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@JsonIgnoreProperties(ignoreUnknown = true)
@Schema(name = "AddingRouteDistributionRuleReqVO", description = "新增路由规则")
public class AddingRouteDistributionRuleReqVO implements Serializable {
    @Serial
    private static final long serialVersionUID = -4614124200425624360L;

    @Schema(description = "策略名称",requiredMode = Schema.RequiredMode.REQUIRED)
    @OperaLogSchema(desc = "策略名称")
    @NotBlank(message = "策略名称不能为空")
    @Size(max = 30, message = "策略名称最多30字符")
    @RequestKeyParam
    private String name;

    @Schema(description = "服务时间id",requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "请设置服务时间")
    private Integer bizTimeId;

    @Schema(description = "服务时间内进线话术",requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "服务时间内进线话术不能为空")
    @Size(max = 30, message = "服务时间内进线话术最多30字符")
    private String workTimeInTip;

    @Schema(description = "非服务时间拦截话术",requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "非服务时间拦截话术不能为空")
    @Size(max = 30, message = "非服务时间拦截话术最多30字符")
    private String restTimeInTip;

    @Schema(description = "路由业务规则",requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "至少设置一条业务规则")
    @Size(min = 1,max = 10,message = "至少设置一条业务规则，最多设置10条")
    @Valid
    private List<RouteBizRuleReqVO> routeBizRuleList;

    @Schema(description = "业务选择错误提示话术",requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "业务选择错误提示话术不能为空")
    @Size(max = 30, message = "业务选择错误提示话术最多30字符")
    private String bizSelectErrorTip;

    @Schema(description = "业务选择错误次数",requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "业务选择错误次数不能为空")
    @Min(value = 1,message = "错误次数范围：1-5")
    @Max(value = 5,message = "错误次数范围：1-5")
    private Integer bizSelectErrorCount;

    @Schema(description = "业务选择错误达到上限次数后操作：0 退出排队；1 随机在配置的业务中分配",requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "业务选择错误达到上限次数后操作不能为空")
    @Min(value = 0,message = "业务选择错误达到上限次数后操作值异常")
    @Max(value = 1,message = "业务选择错误达到上限次数后操作值异常")
    private Integer bizSelectErrorAction;

    @Schema(description = "业务选择错误达到上限次数后退出排队的提示",requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "业务选择错误达到上限次数后退出排序的提示不能为空")
    @Size(max = 300, message = "退出排队话术最多300字符")
    private String bizSelectErrorQuitTip;

    @Schema(description = "访客排队话术",requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "访客排队话术不能为空")
    @Size(max = 300, message = "访客排队话术最多300字符")
    private String queueTip;

    @Schema(description = "退出排队触发词，多个触发词用，隔开",requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "退出排队触发词不能为空")
    @Size(max = 300, message = "退出排队触发词最多300字符")
    private String quitQueueWord;

    @Schema(description = "触发词触发退出排队话术",requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "触发词触发退出排队话术不能为空")
    @Size(max = 300, message = "触发词触发退出排队话术最多300字符")
    private String quitQueueWordTip;

    @Schema(description = "客排队话术播报间隔，单位秒",requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "客排队话术播报间隔不能为空")
    @Min(value = 1,message = "客排队话术播报间隔范围：1-60")
    @Max(value = 60,message = "客排队话术播报间隔范围：1-60")
    private Integer queueTipInterval;

    @Schema(description = "排队超时时间，单位秒",requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "排队超时时间不能为空")
    @Min(value = 1,message = "排队超时时间范围：1-60")
    @Max(value = 60,message = "排队超时时间范围：1-60")
    private Integer queueTimeout;

    @Schema(description = "超时策略：0 溢出其他组；1 退出路由",requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "超时策略不能为空")
    @Min(value = 0,message = "超时策略值异常")
    @Max(value = 1,message = "超时策略间值异常")
    private Integer queueTimeoutType;

    @Schema(description = "超时策略溢出其他组后的技能组配置",requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "超时策略配置不能为空")
    @Valid
    private RouteQueueOverflowCfgReqVO queueTimeoutCfg;

    @Schema(description = "排队时间上限，单位秒",requiredMode = Schema.RequiredMode.REQUIRED)
    @NotNull(message = "排队时间上限不能为空")
    @Min(value = 1,message = "排队时间上限范围：1-60")
    @Max(value = 60,message = "排队时间上限范围：1-60")
    private Integer queueTimeLimit;

    @Schema(description = "排队时间上限触发退出排队话术",requiredMode = Schema.RequiredMode.REQUIRED)
    @NotBlank(message = "排队时间上限触发退出排队话术不能为空")
    @Size(max = 300, message = "排队时间上限触发退出排队话术最多300字符")
    private String quitQueueTimeLimitTip;
}